package com.liuxvru.project.system.controller;

import com.liuxvru.common.annotation.Log;
import com.liuxvru.common.core.controller.BaseController;
import com.liuxvru.common.core.domain.AjaxResult;
import com.liuxvru.common.core.page.TableDataInfo;
import com.liuxvru.common.enums.BusinessType;
import com.liuxvru.common.utils.poi.ExcelUtil;
import com.liuxvru.project.domain.MilestoneWork;
import com.liuxvru.project.service.IMilestoneWorkService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.web.bind.annotation.*;

import javax.servlet.http.HttpServletResponse;
import java.util.List;

/**
 * 里程碑与工作项关联Controller
 *
 * @author liuxvru
 * @date 2024-11-22
 */
@RestController
@RequestMapping("/project/milestoneWork")
public class MilestoneWorkController extends BaseController {
    @Autowired
    private IMilestoneWorkService milestoneWorkService;

    /**
     * 查询里程碑与工作项关联列表
     */
    @PreAuthorize("@ss.hasPermi('project:milestoneWork:list')")
    @GetMapping("/list")
    public TableDataInfo list(MilestoneWork milestoneWork) {
        startPage();
        List<MilestoneWork> list = milestoneWorkService.selectMilestoneWorkList(milestoneWork);
        return getDataTable(list);
    }

    /**
     * 导出里程碑与工作项关联列表
     */
    @PreAuthorize("@ss.hasPermi('project:milestoneWork:export')")
    @Log(title = "里程碑与工作项关联", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, MilestoneWork milestoneWork) {
        List<MilestoneWork> list = milestoneWorkService.selectMilestoneWorkList(milestoneWork);
        ExcelUtil<MilestoneWork> util = new ExcelUtil<MilestoneWork>(MilestoneWork.class);
        util.exportExcel(response, list, "里程碑与工作项关联数据");
    }

    /**
     * 获取里程碑与工作项关联详细信息
     */
    @PreAuthorize("@ss.hasPermi('project:milestoneWork:query')")
    @GetMapping(value = "/{milestoneWorkItemId}")
    public AjaxResult getInfo(@PathVariable("milestoneWorkItemId") Long milestoneWorkItemId) {
        return success(milestoneWorkService.getById(milestoneWorkItemId));
    }

    /**
     * 新增里程碑与工作项关联
     */
    @PreAuthorize("@ss.hasPermi('project:milestoneWork:add')")
    @Log(title = "里程碑与工作项关联", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody MilestoneWork milestoneWork) {
        return toAjax(milestoneWorkService.save(milestoneWork));
    }

    /**
     * 修改里程碑与工作项关联
     */
    @PreAuthorize("@ss.hasPermi('project:milestoneWork:edit')")
    @Log(title = "里程碑与工作项关联", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody MilestoneWork milestoneWork) {
        return toAjax(milestoneWorkService.updateById(milestoneWork));
    }

    /**
     * 删除里程碑与工作项关联
     */
    @PreAuthorize("@ss.hasPermi('project:milestoneWork:remove')")
    @Log(title = "里程碑与工作项关联", businessType = BusinessType.DELETE)
    @DeleteMapping("/{milestoneWorkItemIds}")
    public AjaxResult remove(@PathVariable Long[] milestoneWorkItemIds) {
        return toAjax(milestoneWorkService.removeById(milestoneWorkItemIds));
    }
}
